package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class TestController {

    @GetMapping("/test")
    public Mono<String> mono() throws InterruptedException {
        log.info("开始时间：" + System.currentTimeMillis());
        Mono<String> result = Mono.fromSupplier(this::createStr);
        log.info("结束时间：" + System.currentTimeMillis());
        return result;
    }

    private String createStr() {
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "hello world";
    }
}
